package com.dd.cloud.user.service.pres.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.user.entity.pres.PresHandleRecord;
import com.dd.cloud.common.interceptor.UserInterceptor;
import com.dd.cloud.user.mapper.pres.PresHandleRecordMapper;
import com.dd.cloud.user.req.pres.HandlePresPharmacyReq;
import com.dd.cloud.user.res.pres.PresHandleRecordRes;
import com.dd.cloud.user.service.pres.IPresHandleRecordService;
import com.dd.cloud.common.vo.LoginInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Lx
 * @version 1.0
 */
@Slf4j
@Service
public class PresHandleRecordServiceImpl extends ServiceImpl<PresHandleRecordMapper, PresHandleRecord> implements IPresHandleRecordService {
    /**
     * 添加处方流转处理记录
     *
     * @param req
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addPresHandleRecord(HandlePresPharmacyReq req) {
        LoginInfo loginInfo = UserInterceptor.getLoginUserInfo().get();
        PresHandleRecord presHandleRecord = new PresHandleRecord();
        BeanUtils.copyProperties(req, presHandleRecord);
        presHandleRecord.setCreateId(loginInfo.getId());
        presHandleRecord.setCreateType(loginInfo.getType());
        presHandleRecord.setCreateDate(LocalDateTime.now());
        save(presHandleRecord);
    }

    /**
     * 查询处方流转处理记录
     *
     * @param tencode
     * @return
     */
    @Override
    public List<PresHandleRecordRes> queryPresHandleRecordList(String tencode) {
        return getBaseMapper().queryPresHandleRecordList(tencode);
    }
}
